package 动态规划;

public class 等差数列划分 {
    public int numberOfArithmeticSlices(int[] nums) {
        int  n = nums.length;
        if (n<3)
            return 0;
        //以nums[i]结尾的等差数列个数
        int[] dp = new int[n];
        int ans=0;
        for (int i = 2; i < n; i++) {
            if (2*nums[i-1]==nums[i-2]+nums[i]){
                dp[i] = dp[i-1]+1;
                ans+=dp[i];
            }
        }
        return ans;
    }
}
